#include <iostream>
#include <vector>

using namespace std;
class Solution
{
public:
    int longestOnes(vector<int>& nums, int k)
    {
        int ret = 0;
        for (int left = 0,right=0,zero=0; right < nums.size(); right++)
        {
            if (nums[right] == 0)
                zero++;
            while (zero > k)
            {
                if (nums[left++] == 0)
                    zero--;
            }

            ret = max(ret, right - left + 1);
        }
        return ret;
    }
};
int main()
{
    vector<int> nums{ 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0 };
    int k = 2;

    Solution xz;
    int n = xz.longestOnes(nums, k);
    cout << n << endl;

	return 0;
}